<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>IO::Handle - supply object methods for I/O handles - Perldoc Browser</title>
    <link rel="search" href="https://perldoc.perl.org/opensearch.xml" type="application/opensearchdescription+xml" title="Perldoc Browser">
    <link rel="canonical" href="https://perldoc.perl.org/IO::Handle">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/stackoverflow-light.min.css" integrity="sha512-cG1IdFxqipi3gqLmksLtuk13C+hBa57a6zpWxMeoY3Q9O6ooFxq50DayCdm0QrDgZjMUn23z/0PMZlgft7Yp5Q==" crossorigin="anonymous" />
    <style>
      body {
        background: #f4f4f5;
        color: #020202;
      }
      .navbar-dark {
        background-image: -webkit-linear-gradient(top, #005f85 0, #002e49 100%);
        background-image: -o-linear-gradient(top, #005f85 0, #002e49 100%);
        background-image: linear-gradient(to bottom, #005f85 0, #002e49 100%);
        filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff005f85', endColorstr='#ff002e49', GradientType=0);
        background-repeat: repeat-x;
      }
      .navbar-dark .navbar-nav .nav-link,
      .navbar-dark .navbar-nav .nav-link:focus { color: #fff }
      .navbar-dark .navbar-nav .nav-link:hover { color: #ffef68 }
      #wrapperlicious {
        margin: 0 auto;
        font: 0.9em 'Helvetica Neue', Helvetica, sans-serif;
        font-weight: normal;
        line-height: 1.5em;
        margin: 0;
        padding: 0;
      }
      #wrapperlicious h1 { font-size: 1.5em }
      #wrapperlicious h2 { font-size: 1.3em }
      #wrapperlicious h3 { font-size: 1.1em }
      #wrapperlicious h4 { font-size: 0.9em }
      #wrapperlicious h1, #wrapperlicious h2, #wrapperlicious h3,
      #wrapperlicious h4, #wrapperlicious dt {
        color: #020202;
        margin-top: 1em;
        margin-bottom: 1em;
        position: relative;
        font-weight: bold;
      }
      #wrapperlicious a { color: inherit; text-decoration: underline }
      #wrapperlicious #toc { text-decoration: none }
      #wrapperlicious a:hover { color: #2a2a2a }
      #wrapperlicious a img { border: 0 }
      #wrapperlicious :not(pre) > code {
        color: inherit;
        background-color: rgba(0, 0, 0, 0.04);
        border-radius: 3px;
        font: 0.9em Consolas, Menlo, Monaco, monospace;
        padding: 0.3em;
      }
      #wrapperlicious dd {
        margin: 0;
        margin-left: 2em;
      }
      #wrapperlicious dt {
        color: #2a2a2a;
        font-weight: bold;
        margin-left: 0.9em;
      }
      #wrapperlicious p {
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious li > p {
        margin-bottom: 0;
        margin-top: 0;
      }
      #wrapperlicious pre {
        border: 1px solid #c1c1c1;
        border-radius: 3px;
        font: 100% Consolas, Menlo, Monaco, monospace;
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious pre > code {
        display: block;
        background-color: #f6f6f6;
        font: 0.9em Consolas, Menlo, Monaco, monospace;
        line-height: 1.5em;
        text-align: left;
        white-space: pre;
        padding: 1em;
      }
      #wrapperlicious dl, #wrapperlicious ol, #wrapperlicious ul {
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious ul {
        list-style-type: square;
      }
      #wrapperlicious ul ul {
        margin-bottom: 0px;
        margin-top: 0px;
      }
      #footer {
        font-size: 0.8em;
        padding-top: 0.5em;
        text-align: center;
      }
      #more {
        display: inline;
        font-size: 0.8em;
      }
      #perldocdiv {
        background-color: #fff;
        border: 1px solid #c1c1c1;
        border-bottom-left-radius: 5px;
        border-bottom-right-radius: 5px;
        margin-left: auto;
        margin-right: auto;
        padding: 3em;
        padding-top: 1em;
        max-width: 960px;
      }
      #moduleversion { float: right }
      #wrapperlicious .leading-notice {
        font-style: italic;
        padding-left: 1em;
        margin-top: 1em;
        margin-bottom: 1em;
      }
      #wrapperlicious .permalink {
        display: none;
        left: -0.75em;
        position: absolute;
        padding-right: 0.25em;
        text-decoration: none;
      }
      #wrapperlicious h1:hover .permalink, #wrapperlicious h2:hover .permalink,
      #wrapperlicious h3:hover .permalink, #wrapperlicious h4:hover .permalink,
      #wrapperlicious dt:hover .permalink {
        display: block;
      }
    </style>
    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=G-KVNWBNT5FB"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());

      gtag('config', 'G-KVNWBNT5FB');
      gtag('config', 'UA-50555-3');
    </script>
  </head>
  <body>
    <nav class="navbar navbar-expand-md navbar-dark bg-dark justify-content-between">
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <a class="navbar-brand" href="https://perldoc.perl.org/">Perldoc Browser</a>
  <div class="collapse navbar-collapse" id="navbarNav">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="./IO::Handle.html#" id="dropdownlink-stable" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">5.35.0</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-stable">
          <a class="dropdown-item" href="https://perldoc.perl.org/IO::Handle">Latest</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.2/IO::Handle">5.38.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.1/IO::Handle">5.38.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0/IO::Handle">5.38.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.3/IO::Handle">5.36.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.2/IO::Handle">5.36.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.1/IO::Handle">5.36.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.0/IO::Handle">5.36.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.3/IO::Handle">5.34.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.2/IO::Handle">5.34.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.1/IO::Handle">5.34.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.0/IO::Handle">5.34.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.32.1/IO::Handle">5.32.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.32.0/IO::Handle">5.32.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.3/IO::Handle">5.30.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.2/IO::Handle">5.30.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.1/IO::Handle">5.30.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.0/IO::Handle">5.30.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.3/IO::Handle">5.28.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.2/IO::Handle">5.28.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.1/IO::Handle">5.28.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.0/IO::Handle">5.28.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.3/IO::Handle">5.26.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.2/IO::Handle">5.26.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.1/IO::Handle">5.26.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.0/IO::Handle">5.26.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.4/IO::Handle">5.24.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.3/IO::Handle">5.24.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.2/IO::Handle">5.24.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.1/IO::Handle">5.24.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.0/IO::Handle">5.24.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.4/IO::Handle">5.22.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.3/IO::Handle">5.22.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.2/IO::Handle">5.22.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.1/IO::Handle">5.22.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.0/IO::Handle">5.22.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.3/IO::Handle">5.20.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.2/IO::Handle">5.20.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.1/IO::Handle">5.20.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.0/IO::Handle">5.20.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.4/IO::Handle">5.18.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.3/IO::Handle">5.18.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.2/IO::Handle">5.18.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.1/IO::Handle">5.18.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.0/IO::Handle">5.18.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.3/IO::Handle">5.16.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.2/IO::Handle">5.16.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.1/IO::Handle">5.16.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.0/IO::Handle">5.16.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.4/IO::Handle">5.14.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.3/IO::Handle">5.14.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.2/IO::Handle">5.14.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.1/IO::Handle">5.14.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.0/IO::Handle">5.14.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.5/IO::Handle">5.12.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.4/IO::Handle">5.12.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.3/IO::Handle">5.12.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.2/IO::Handle">5.12.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.1/IO::Handle">5.12.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.0/IO::Handle">5.12.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.10.1/IO::Handle">5.10.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.10.0/IO::Handle">5.10.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.9/IO::Handle">5.8.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.8/IO::Handle">5.8.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.7/IO::Handle">5.8.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.6/IO::Handle">5.8.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.5/IO::Handle">5.8.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.4/IO::Handle">5.8.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.3/IO::Handle">5.8.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.2/IO::Handle">5.8.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.1/IO::Handle">5.8.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.0/IO::Handle">5.8.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.2/IO::Handle">5.6.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.1/IO::Handle">5.6.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.0/IO::Handle">5.6.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_04/IO::Handle">5.005_04</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_03/IO::Handle">5.005_03</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_02/IO::Handle">5.005_02</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_01/IO::Handle">5.005_01</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005/IO::Handle">5.005</a>
        </div>
      </li>
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="./IO::Handle.html#" id="dropdownlink-dev" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dev</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-dev">
          <a class="dropdown-item" href="https://perldoc.perl.org/blead/IO::Handle">blead</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.6/IO::Handle">5.39.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.5/IO::Handle">5.39.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.4/IO::Handle">5.39.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.3/IO::Handle">5.39.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.2/IO::Handle">5.39.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.1/IO::Handle">5.39.1</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0-RC2/IO::Handle">5.38.0-RC2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0-RC1/IO::Handle">5.38.0-RC1</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.11/IO::Handle">5.37.11</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.10/IO::Handle">5.37.10</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.9/IO::Handle">5.37.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.8/IO::Handle">5.37.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.7/IO::Handle">5.37.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.6/IO::Handle">5.37.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.5/IO::Handle">5.37.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.4/IO::Handle">5.37.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.3/IO::Handle">5.37.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.2/IO::Handle">5.37.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.1/IO::Handle">5.37.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.0/IO::Handle">5.37.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.11/IO::Handle">5.35.11</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.10/IO::Handle">5.35.10</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.9/IO::Handle">5.35.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.8/IO::Handle">5.35.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.7/IO::Handle">5.35.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.6/IO::Handle">5.35.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.5/IO::Handle">5.35.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.4/IO::Handle">5.35.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.3/IO::Handle">5.35.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.2/IO::Handle">5.35.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.1/IO::Handle">5.35.1</a>
          <a class="dropdown-item active" href="./IO::Handle.html">5.35.0</a>
        </div>
      </li>
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="./IO::Handle.html#" id="dropdownlink-nav" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Documentation</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-nav">
          <a class="dropdown-item" href="perl.html">Perl</a>
          <a class="dropdown-item" href="perlintro.html">Intro</a>
          <a class="dropdown-item" href="perl.html#Tutorials">Tutorials</a>
          <a class="dropdown-item" href="perlfaq.html">FAQs</a>
          <a class="dropdown-item" href="perl.html#Reference-Manual">Reference</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="perlop.html">Operators</a>
          <a class="dropdown-item" href="functions.html">Functions</a>
          <a class="dropdown-item" href="variables.html">Variables</a>
          <a class="dropdown-item" href="modules.html">Modules</a>
          <a class="dropdown-item" href="perlutil.html">Utilities</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="perlcommunity.html">Community</a>
          <a class="dropdown-item" href="perlhist.html">History</a>
        </div>
      </li>
    </ul>
    <ul class="navbar-nav">
      <script>
        function set_expand (expand) {
          var perldocdiv = document.getElementById('perldocdiv');
          var width = window.getComputedStyle(perldocdiv).getPropertyValue('max-width');
          var expanded = (width == '' || width == 'none') ? true : false;
          if (expand === null) {
            expand = !expanded;
          }
          if ((expand && !expanded) || (!expand && expanded)) {
            perldocdiv.style.setProperty('max-width', expand ? 'none' : '960px');
            var button_classlist = document.getElementById('content-expand-button').classList;
            if (expand) {
              button_classlist.add('btn-light');
              button_classlist.remove('btn-outline-light');
            } else {
              button_classlist.add('btn-outline-light');
              button_classlist.remove('btn-light');
            }
          }
          return expand;
        }
        function toggle_expand () {
          var expand = set_expand(null);
          document.cookie = 'perldoc_expand=' + (expand ? 1 : 0) + '; path=/; expires=Tue, 19 Jan 2038 03:14:07 UTC';
        }
        function read_expand () {
          return document.cookie.split(';').some(function (item) { return item.indexOf('perldoc_expand=1') >= 0 });
        }
        if (document.readyState === 'loading') {
          document.addEventListener('DOMContentLoaded', function () {
            if (read_expand()) {
              set_expand(true);
            }
          });
        } else if (read_expand()) {
          set_expand(true);
        }
      </script>
      <button id="content-expand-button" type="button" class="btn btn-outline-light d-none d-lg-inline-block mr-2" onclick="toggle_expand()">Expand</button>
    <ul>
    <form class="form-inline" method="get" action="https://perldoc.perl.org/5.35.0/search">
      <input class="form-control mr-3" type="search" name="q" placeholder="Search" aria-label="Search">
    </form>
  </div>
</nav>

    <div id="wrapperlicious" class="container-fluid">
      <div id="perldocdiv">
        <div id="links">
          <a href="./IO::Handle.html">IO::Handle</a>
          <div id="more">
            (<a href="./IO::Handle.txt">source</a>,
            <a href="https://metacpan.org/pod/IO::Handle">CPAN</a>)
          </div>
            <div id="moduleversion">version 1.46</div>
        </div>
        <div class="leading-notice">
          You are viewing the version of this documentation from Perl 5.35.0.
            This is a development version of Perl.
        </div>
        <h1><a id="toc">CONTENTS</a></h1>
                  <ul>
              <li>
                <a class="text-decoration-none" href="./IO::Handle.html#NAME">NAME</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Handle.html#SYNOPSIS">SYNOPSIS</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Handle.html#DESCRIPTION">DESCRIPTION</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Handle.html#CONSTRUCTOR">CONSTRUCTOR</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Handle.html#METHODS">METHODS</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Handle.html#NOTE">NOTE</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Handle.html#SEE-ALSO">SEE ALSO</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Handle.html#BUGS">BUGS</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Handle.html#HISTORY">HISTORY</a>
              </li>
          </ul>

      <h1 id="NAME"><a class="permalink" href="./IO::Handle.html#NAME">#</a>NAME</h1>

<p>IO::Handle - supply object methods for I/O handles</p>

<h1 id="SYNOPSIS"><a class="permalink" href="./IO::Handle.html#SYNOPSIS">#</a>SYNOPSIS</h1>

<pre><code>use IO::Handle;

$io = IO::Handle-&gt;new();
if ($io-&gt;fdopen(fileno(STDIN),&quot;r&quot;)) {
    print $io-&gt;getline;
    $io-&gt;close;
}

$io = IO::Handle-&gt;new();
if ($io-&gt;fdopen(fileno(STDOUT),&quot;w&quot;)) {
    $io-&gt;print(&quot;Some text\n&quot;);
}

# setvbuf is not available by default on Perls 5.8.0 and later.
use IO::Handle &#39;_IOLBF&#39;;
$io-&gt;setvbuf($buffer_var, _IOLBF, 1024);

undef $io;       # automatically closes the file if it&#39;s open

autoflush STDOUT 1;</code></pre>

<h1 id="DESCRIPTION"><a class="permalink" href="./IO::Handle.html#DESCRIPTION">#</a>DESCRIPTION</h1>

<p><code>IO::Handle</code> is the base class for all other IO handle classes. It is not intended that objects of <code>IO::Handle</code> would be created directly, but instead <code>IO::Handle</code> is inherited from by several other classes in the IO hierarchy.</p>

<p>If you are reading this documentation, looking for a replacement for the <code>FileHandle</code> package, then I suggest you read the documentation for <code>IO::File</code> too.</p>

<h1 id="CONSTRUCTOR"><a class="permalink" href="./IO::Handle.html#CONSTRUCTOR">#</a>CONSTRUCTOR</h1>

<dl>

<dt id="new-()"><a class="permalink" href="./IO::Handle.html#new-()">#</a><a id="new"></a>new ()</dt>
<dd>

<p>Creates a new <code>IO::Handle</code> object.</p>

</dd>
<dt id="new_from_fd-(-FD,-MODE-)"><a class="permalink" href="./IO::Handle.html#new_from_fd-(-FD,-MODE-)">#</a><a id="new_from_fd"></a><a id="new_from_fd-FD-MODE"></a>new_from_fd ( FD, MODE )</dt>
<dd>

<p>Creates an <code>IO::Handle</code> like <code>new</code> does. It requires two parameters, which are passed to the method <code>fdopen</code>; if the fdopen fails, the object is destroyed. Otherwise, it is returned to the caller.</p>

</dd>
</dl>

<h1 id="METHODS"><a class="permalink" href="./IO::Handle.html#METHODS">#</a>METHODS</h1>

<p>See <a href="perlfunc.html">perlfunc</a> for complete descriptions of each of the following supported <code>IO::Handle</code> methods, which are just front ends for the corresponding built-in functions:</p>

<pre><code>$io-&gt;close
$io-&gt;eof
$io-&gt;fcntl( FUNCTION, SCALAR )
$io-&gt;fileno
$io-&gt;format_write( [FORMAT_NAME] )
$io-&gt;getc
$io-&gt;ioctl( FUNCTION, SCALAR )
$io-&gt;read ( BUF, LEN, [OFFSET] )
$io-&gt;print ( ARGS )
$io-&gt;printf ( FMT, [ARGS] )
$io-&gt;say ( ARGS )
$io-&gt;stat
$io-&gt;sysread ( BUF, LEN, [OFFSET] )
$io-&gt;syswrite ( BUF, [LEN, [OFFSET]] )
$io-&gt;truncate ( LEN )</code></pre>

<p>See <a href="perlvar.html">perlvar</a> for complete descriptions of each of the following supported <code>IO::Handle</code> methods. All of them return the previous value of the attribute and takes an optional single argument that when given will set the value. If no argument is given the previous value is unchanged (except for $io-&gt;autoflush will actually turn ON autoflush by default).</p>

<pre><code>$io-&gt;autoflush ( [BOOL] )                         $|
$io-&gt;format_page_number( [NUM] )                  $%
$io-&gt;format_lines_per_page( [NUM] )               $=
$io-&gt;format_lines_left( [NUM] )                   $-
$io-&gt;format_name( [STR] )                         $~
$io-&gt;format_top_name( [STR] )                     $^
$io-&gt;input_line_number( [NUM])                    $.</code></pre>

<p>The following methods are not supported on a per-filehandle basis.</p>

<pre><code>IO::Handle-&gt;format_line_break_characters( [STR] ) $:
IO::Handle-&gt;format_formfeed( [STR])               $^L
IO::Handle-&gt;output_field_separator( [STR] )       $,
IO::Handle-&gt;output_record_separator( [STR] )      $\

IO::Handle-&gt;input_record_separator( [STR] )       $/</code></pre>

<p>Furthermore, for doing normal I/O you might need these:</p>

<dl>

<dt id="$io-&gt;fdopen-(-FD,-MODE-)"><a class="permalink" href="./IO::Handle.html#$io-%3Efdopen-(-FD,-MODE-)">#</a><a id="fdopen"></a><a id="io-fdopen-FD-MODE"></a>$io-&gt;fdopen ( FD, MODE )</dt>
<dd>

<p><code>fdopen</code> is like an ordinary <code>open</code> except that its first parameter is not a filename but rather a file handle name, an IO::Handle object, or a file descriptor number. (For the documentation of the <code>open</code> method, see <a href="./IO::File.html">IO::File</a>.)</p>

</dd>
<dt id="$io-&gt;opened"><a class="permalink" href="./IO::Handle.html#$io-%3Eopened">#</a><a id="opened"></a><a id="io-opened"></a>$io-&gt;opened</dt>
<dd>

<p>Returns true if the object is currently a valid file descriptor, false otherwise.</p>

</dd>
<dt id="$io-&gt;getline"><a class="permalink" href="./IO::Handle.html#$io-%3Egetline">#</a><a id="getline"></a><a id="io-getline"></a>$io-&gt;getline</dt>
<dd>

<p>This works like &lt;$io&gt; described in <a href="perlop.html#I%2FO-Operators">&quot;I/O Operators&quot; in perlop</a> except that it&#39;s more readable and can be safely called in a list context but still returns just one line. If used as the conditional within a <code>while</code> or C-style <code>for</code> loop, however, you will need to emulate the functionality of &lt;$io&gt; with <code>defined($_ = $io-&gt;getline)</code>.</p>

</dd>
<dt id="$io-&gt;getlines"><a class="permalink" href="./IO::Handle.html#$io-%3Egetlines">#</a><a id="getlines"></a><a id="io-getlines"></a>$io-&gt;getlines</dt>
<dd>

<p>This works like &lt;$io&gt; when called in a list context to read all the remaining lines in a file, except that it&#39;s more readable. It will also croak() if accidentally called in a scalar context.</p>

</dd>
<dt id="$io-&gt;ungetc-(-ORD-)"><a class="permalink" href="./IO::Handle.html#$io-%3Eungetc-(-ORD-)">#</a><a id="ungetc"></a><a id="io-ungetc-ORD"></a>$io-&gt;ungetc ( ORD )</dt>
<dd>

<p>Pushes a character with the given ordinal value back onto the given handle&#39;s input stream. Only one character of pushback per handle is guaranteed.</p>

</dd>
<dt id="$io-&gt;write-(-BUF,-LEN-[,-OFFSET-]-)"><a class="permalink" href="./IO::Handle.html#$io-%3Ewrite-(-BUF,-LEN-%5B,-OFFSET-%5D-)">#</a><a id="write"></a><a id="io-write-BUF-LEN-OFFSET"></a>$io-&gt;write ( BUF, LEN [, OFFSET ] )</dt>
<dd>

<p>This <code>write</code> is somewhat like <code>write</code> found in C, in that it is the opposite of read. The wrapper for the perl <code>write</code> function is called <code>format_write</code>. However, whilst the C <code>write</code> function returns the number of bytes written, this <code>write</code> function simply returns true if successful (like <code>print</code>). A more C-like <code>write</code> is <code>syswrite</code> (see above).</p>

</dd>
<dt id="$io-&gt;error"><a class="permalink" href="./IO::Handle.html#$io-%3Eerror">#</a><a id="error"></a><a id="io-error"></a>$io-&gt;error</dt>
<dd>

<p>Returns a true value if the given handle has experienced any errors since it was opened or since the last call to <code>clearerr</code>, or if the handle is invalid. It only returns false for a valid handle with no outstanding errors.</p>

</dd>
<dt id="$io-&gt;clearerr"><a class="permalink" href="./IO::Handle.html#$io-%3Eclearerr">#</a><a id="clearerr"></a><a id="io-clearerr"></a>$io-&gt;clearerr</dt>
<dd>

<p>Clear the given handle&#39;s error indicator. Returns -1 if the handle is invalid, 0 otherwise.</p>

</dd>
<dt id="$io-&gt;sync"><a class="permalink" href="./IO::Handle.html#$io-%3Esync">#</a><a id="sync"></a><a id="io-sync"></a>$io-&gt;sync</dt>
<dd>

<p><code>sync</code> synchronizes a file&#39;s in-memory state with that on the physical medium. <code>sync</code> does not operate at the perlio api level, but operates on the file descriptor (similar to sysread, sysseek and systell). This means that any data held at the perlio api level will not be synchronized. To synchronize data that is buffered at the perlio api level you must use the flush method. <code>sync</code> is not implemented on all platforms. Returns &quot;0 but true&quot; on success, <code>undef</code> on error, <code>undef</code> for an invalid handle. See <a>fsync(3c)</a>.</p>

</dd>
<dt id="$io-&gt;flush"><a class="permalink" href="./IO::Handle.html#$io-%3Eflush">#</a><a id="flush"></a><a id="io-flush"></a>$io-&gt;flush</dt>
<dd>

<p><code>flush</code> causes perl to flush any buffered data at the perlio api level. Any unread data in the buffer will be discarded, and any unwritten data will be written to the underlying file descriptor. Returns &quot;0 but true&quot; on success, <code>undef</code> on error.</p>

</dd>
<dt id="$io-&gt;printflush-(-ARGS-)"><a class="permalink" href="./IO::Handle.html#$io-%3Eprintflush-(-ARGS-)">#</a><a id="printflush"></a><a id="io-printflush-ARGS"></a>$io-&gt;printflush ( ARGS )</dt>
<dd>

<p>Turns on autoflush, print ARGS and then restores the autoflush status of the <code>IO::Handle</code> object. Returns the return value from print.</p>

</dd>
<dt id="$io-&gt;blocking-(-[-BOOL-]-)"><a class="permalink" href="./IO::Handle.html#$io-%3Eblocking-(-%5B-BOOL-%5D-)">#</a><a id="blocking"></a><a id="io-blocking-BOOL"></a>$io-&gt;blocking ( [ BOOL ] )</dt>
<dd>

<p>If called with an argument <code>blocking</code> will turn on non-blocking IO if <code>BOOL</code> is false, and turn it off if <code>BOOL</code> is true.</p>

<p><code>blocking</code> will return the value of the previous setting, or the current setting if <code>BOOL</code> is not given.</p>

<p>If an error occurs <code>blocking</code> will return undef and <code>$!</code> will be set.</p>

</dd>
</dl>

<p>If the C functions setbuf() and/or setvbuf() are available, then <code>IO::Handle::setbuf</code> and <code>IO::Handle::setvbuf</code> set the buffering policy for an IO::Handle. The calling sequences for the Perl functions are the same as their C counterparts--including the constants <code>_IOFBF</code>, <code>_IOLBF</code>, and <code>_IONBF</code> for setvbuf()--except that the buffer parameter specifies a scalar variable to use as a buffer. You should only change the buffer before any I/O, or immediately after calling flush.</p>

<p>WARNING: The IO::Handle::setvbuf() is not available by default on Perls 5.8.0 and later because setvbuf() is rather specific to using the stdio library, while Perl prefers the new perlio subsystem instead.</p>

<p>WARNING: A variable used as a buffer by <code>setbuf</code> or <code>setvbuf</code> <b>must not be modified</b> in any way until the IO::Handle is closed or <code>setbuf</code> or <code>setvbuf</code> is called again, or memory corruption may result! Remember that the order of global destruction is undefined, so even if your buffer variable remains in scope until program termination, it may be undefined before the file IO::Handle is closed. Note that you need to import the constants <code>_IOFBF</code>, <code>_IOLBF</code>, and <code>_IONBF</code> explicitly. Like C, setbuf returns nothing. setvbuf returns &quot;0 but true&quot;, on success, <code>undef</code> on failure.</p>

<p>Lastly, there is a special method for working under <b>-T</b> and setuid/gid scripts:</p>

<dl>

<dt id="$io-&gt;untaint"><a class="permalink" href="./IO::Handle.html#$io-%3Euntaint">#</a><a id="untaint"></a><a id="io-untaint"></a>$io-&gt;untaint</dt>
<dd>

<p>Marks the object as taint-clean, and as such data read from it will also be considered taint-clean. Note that this is a very trusting action to take, and appropriate consideration for the data source and potential vulnerability should be kept in mind. Returns 0 on success, -1 if setting the taint-clean flag failed. (eg invalid handle)</p>

</dd>
</dl>

<h1 id="NOTE"><a class="permalink" href="./IO::Handle.html#NOTE">#</a>NOTE</h1>

<p>An <code>IO::Handle</code> object is a reference to a symbol/GLOB reference (see the <code>Symbol</code> package). Some modules that inherit from <code>IO::Handle</code> may want to keep object related variables in the hash table part of the GLOB. In an attempt to prevent modules trampling on each other I propose the that any such module should prefix its variables with its own name separated by _&#39;s. For example the IO::Socket module keeps a <code>timeout</code> variable in &#39;io_socket_timeout&#39;.</p>

<h1 id="SEE-ALSO"><a class="permalink" href="./IO::Handle.html#SEE-ALSO">#</a><a id="SEE"></a>SEE ALSO</h1>

<p><a href="perlfunc.html">perlfunc</a>, <a href="perlop.html#I%2FO-Operators">&quot;I/O Operators&quot; in perlop</a>, <a href="./IO::File.html">IO::File</a></p>

<h1 id="BUGS"><a class="permalink" href="./IO::Handle.html#BUGS">#</a>BUGS</h1>

<p>Due to backwards compatibility, all filehandles resemble objects of class <code>IO::Handle</code>, or actually classes derived from that class. They actually aren&#39;t. Which means you can&#39;t derive your own class from <code>IO::Handle</code> and inherit those methods.</p>

<h1 id="HISTORY"><a class="permalink" href="./IO::Handle.html#HISTORY">#</a>HISTORY</h1>

<p>Derived from FileHandle.pm by Graham Barr &lt;<i>gbarr@pobox.com</i>&gt;</p>


      </div>
      <div id="footer">
        <p>Perldoc Browser is maintained by Dan Book (<a href="https://metacpan.org/author/DBOOK">DBOOK</a>). Please contact him via the <a href="https://github.com/Grinnz/perldoc-browser/issues">GitHub issue tracker</a> or <a href="mailto:dbook@cpan.org">email</a> regarding any issues with the site itself, search, or rendering of documentation.</p>

<p>The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via the <a href="https://github.com/Perl/perl5/issues">Perl issue tracker</a>, the <a href="https://lists.perl.org/list/perl5-porters.html">mailing list</a>, or <a href="https://kiwiirc.com/client/irc.perl.org/p5p">IRC</a> to report any issues with the contents or format of the documentation.</p>


      </div>
    </div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.slim.min.js" integrity="sha512-/DXTXr6nQodMUiq+IUJYCt2PPOUjrHJ9wFrqpJ3XkgPNOZVfMok7cRw6CSxyCQxXn6ozlESsSh1/sMCTF1rL/g==" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.1/umd/popper.min.js" integrity="sha512-ubuT8Z88WxezgSqf3RLuNi5lmjstiJcyezx34yIU2gAHonIi27Na7atqzUZCOoY4CExaoFumzOsFQ2Ch+I/HCw==" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
    <script src="../highlight.pack.js"></script>
    <script>hljs.highlightAll();</script>
  </body>
</html>
